package com.yyk.yykywd.util

import android.app.Activity
import android.content.Context
import android.content.Intent
import com.orhanobut.logger.Logger
import com.yyk.yykywd.*
import com.yyk.yykywd.config.HttpUrl
import com.yyk.yykywd.http.Api
import com.yyk.yykywd.mvvm.ui.*
import com.yyk.yykywd.ui.MainActivity
import com.yyk.yykywd.ui.WebActivity
import com.yyk.yykywd.ui.YewutongzhiActivity
import com.yyk.yykywd.ui.work.CardWebActivity

/**
 * 文件描述：
 * Created by guo on 2019-11-18.
 */
object ToAnotherActivity {
    fun toMainActivity(context: Context) {
        toCommonActivity(context, MainActivity::class.java)
    }

    fun toYewutongzhiActivity(context: Context) {
        toCommonActivity(context, YewutongzhiActivity::class.java)
    }

    fun toWebActivity(context: Context, url: String, title: String) {
        val intent = newIntent(context, WebActivity::class.java)
        Logger.e("h5网址$url")
        intent.putExtra("url", url)
        intent.putExtra("title", title)
        context.startActivity(intent)
    }

    /**
     * 跳转到签订合同详情或者回款完成详情
     */
    fun toDetailActivity(context: Context, type: String, id: String, show_type: Int) {
        val intent = newIntent(context, WorkDetail1Activity::class.java)
        withId(intent, id)
        withType(intent, type)
        intent.putExtra(SHOW_TYPE, show_type)
        context.startActivity(intent)
    }

    fun toReturnMoneyDetailActivity(context: Context, type: String, id: String,
                                    flag: Int, show_type: Int, type_s: Int) {
        val intent = newIntent(context, WorkDetailActivity::class.java)
        withId(intent, id)
        withType(intent, type)
        intent.putExtra(FLAG, flag)
        intent.putExtra(SHOW_TYPE, show_type)
        intent.putExtra(TYPE_S, type_s)
        context.startActivity(intent)
    }

    /**
     * 跳转到创建或修改会议邀约界面
     */
    fun toCreateOrModifyMeetingInvitationActivity(context: Context, type: String, id: String) {
        val intent = newIntent(context, ModifyMeetingInvitationActivity::class.java)
        withId(intent, id)
        withType(intent, type)
        context.startActivity(intent)
    }

    fun toMeetingInvitationDetailActivity(context: Context, id: String) {
        val intent = newIntent(context, MeetingInvitationDetailActivity::class.java)
        withId(intent, id)
        context.startActivity(intent)
    }

    /**
     * 跳转到全款合同或者安装医院列表页
     */
    fun toReturnMoneyActivity(context: Context, type: String) {
        val intent = newIntent(context, ReturnMoneyActivity::class.java)
        withType(intent, type)
        context.startActivity(intent)
    }

    fun toMeetingInvitationActivity(context: Context, type: String) {
        val intent = newIntent(context, MeetingInvitationActivity::class.java)
        withType(intent, type)
        if (type == FROM_WORK) {
            context.startActivity(intent)
        } else {
            (context as Activity).startActivityForResult(intent, FOLLOW_CODE)
        }
    }

    /**
     * 跳转到业务跟进界面
     */
    fun toBusinessFollowActivity(context: Context, type: String,
                                 id: String,
                                 name: String,
                                 position: String,
                                 phone: String) {
        val intent = newIntent(context, BusinessFollowActivity::class.java)
        withType(intent, type)
        withId(intent, id)
        intent.putExtra(VISITOR_NAME, name)
        intent.putExtra(VISITOR_POSITION, position)
        intent.putExtra(VISITOR_PHONE, phone)
        context.startActivity(intent)
    }

    /**
     * 跳转到医院上传合同界面
     */
    fun toUploadContractActivity(context: Context, type: String, id: String) {
        val intent = newIntent(context, UploadContractActivity::class.java)
        withType(intent, type)
        withId(intent, id)
        context.startActivity(intent)
    }

    /**
     * 跳转到意向客户列表或者签订合同列表界面
     */
    fun toPotentialCustomerActivity(context: Context, type: String) {
        val intent = newIntent(context, PotentialCustomerActivity::class.java)
        withType(intent, type)
        context.startActivity(intent)
    }

    /**
     * 跳转到添加回款界面
     */
    fun toAddReturnActivity(context: Context, position: Int, id: String, type: String, pact_id: String) {
        val intent = newIntent(context, AddReturnMoneyActivity::class.java)
        withId(intent, id)
        withType(intent, type)
        intent.putExtra(POSITION, position)
        intent.putExtra(PACT_ID, pact_id)
        context.startActivity(intent)
    }

    /**
     * 跳转到补全合同界面
     */
    fun toCompletionContractActivity(context: Context, id: String, pact_id: String,
                                     back_money_num: Int,
                                     rxhk_money: Int) {
        val intent = newIntent(context, CompletionContractActivity::class.java)
        withId(intent, id)
        intent.putExtra(PACT_ID, pact_id)
        intent.putExtra(BACK_MONEY_NUM, back_money_num)
        intent.putExtra(RXHK_MONEY, rxhk_money)
        context.startActivity(intent)
    }

    /**
     * 跳转到代理商退款界面
     */
    fun toAgentRefundActivity(context: Context, refund_num: Int,
                              back_money_num: Int, name: String, pact_id: String, id: String, money: String) {
        val intent = newIntent(context, AgentRefundActivity::class.java)
        withId(intent, id)
        withMoney(intent, money)
        intent.putExtra(PACT_ID, pact_id)
        intent.putExtra(REFUND_NUM, refund_num)
        intent.putExtra(BACK_MONEY_NUM, back_money_num)
        intent.putExtra(NAME, name)
        context.startActivity(intent)
    }

    /**
     * 跳转到认领客户界面
     */
    fun toClaimCustomerActivity(context: Context, id: String, type: String) {
        val intent = newIntent(context, ClaimCustomerActivity::class.java)
        withId(intent, id)
        withType(intent, type)
        context.startActivity(intent)
    }

    fun toDynamicBroadcastActivity(context: Context, id: String) {
        val intent = newIntent(context, DynamicBroadcastActivity::class.java)
        withId(intent, id)
        context.startActivity(intent)
    }

    /**
     * 跳转到合同图片界面
     */
    fun toContractImgActivity(context: Context, contracts: ArrayList<String>) {
        val intent = newIntent(context, ContractImgActivity::class.java)
        intent.putStringArrayListExtra(CONTRACT_IMG, contracts)
        context.startActivity(intent)
    }

    /**
     * 图片详情
     *
     * @param context
     * @param pic
     */
    fun toPicActivity(context: Context, pic: String) {
        val intent = newIntent(context, PicDetailActivity::class.java)
        intent.putExtra(IMG, pic)
        context.startActivity(intent)
    }

    /**
     * 跳转到会议结束界面
     */
    fun toMeetingEndActivity(context: Context, id: String) {
        val intent = newIntent(context, MeetingEndActivity::class.java)
        withId(intent, id)
        context.startActivity(intent)
    }

    /**
     * 跳转到用户协议或者隐私政策界面
     */
    fun toAgreementActivity(context: Context, type: String) {
        val intent = newIntent(context, UserAgreementActivity::class.java)
        withType(intent, type)
        context.startActivity(intent)
    }

    /**
     * 跳转到搜索客户界面
     */
    fun toSearchCustomerActivity(context: Context, type: String) {
        val intent = newIntent(context, SearchCustomerActivity::class.java)
        withType(intent, type)
        context.startActivity(intent)
    }

    fun toCommonActivity(context: Context, cls: Class<*>) {
        val intent = newIntent(context, cls)
        context.startActivity(intent)
    }

    fun toCardWebActivity(context: Context) {
        val intent = newIntent(context, CardWebActivity::class.java)
        context.startActivity(intent)
    }

    private fun newIntent(context: Context, cls: Class<*>): Intent {
        return Intent(context, cls)
    }

    private fun withId(intent: Intent, id: String) {
        intent.putExtra(ID, id)
    }

    private fun withMoney(intent: Intent, money: String) {
        intent.putExtra(MONEY, money)
    }

    private fun withType(intent: Intent, type: String) {
        intent.putExtra(TYPE, type)
    }

    private fun withStatus(intent: Intent, status: String) {
        intent.putExtra(STATUS, status)
    }
}